# line = 'qwedeesdccddxddd'
#
#
# def retrun_count(fname):
#     """计算文件有多少行
#     """
#     count = 0
#     with open(fname) as file:
#         for line in file:
#             count += 1
#     return count







#
# def return_count_v2(fname):
#
#     count = 0
#     block_size = 1024 * 8
#     with open(fname) as fp:
#         while True:
#             chunk = fp.read(block_size)
#             # 当文件没有更多内容时，read 调用将会返回空字符串 ''
#             if not chunk:
#                 break
#             count += 1
#     return count



import random

list_arr = ['l','z','y','6','7','8']


def write_file():
    # 先定义一个计数count
    count = 0
    # 打开文件别写入
    with open('ttt.txt','w') as file:
        # 循环判断count是否大于1024
        while count <= 1024:
            # 随机写入list_arr中的元素
            file.write(list_arr[random.randint(0,len(list_arr) - 1)])
            # 每写一个数就计数加一
            count += 1

# write_file()


file_name = 'yd.txt'
# 设置每次读取阈值
size = 1024 * 8


def reads_file():
    # 打开文件
    with open(file_name,'r') as du:
        # 接收内容变量
        count = 1
        while count:
            count = du.read(size)
            # 变成生成器
            yield count

files_yd = reads_file()

for files in files_yd:
    print(files)







